<html xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jstl/core"
      xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:t="http://myfaces.apache.org/tomahawk">

<f:view>
<f:loadBundle var="text" basename="#{testInstanceList.bundleName}"/>
<f:loadBundle var="textEnv" basename="env"/>
    <head>
        <title>#{text['testInstance.title']}</title>
        <meta name="heading" content="#{text['testInstance.heading']}"/>
        <meta name="menu" content="MyTestsMenu"/>
    </head>
<body id="userInstanceList">

<!-- Messages displayed -->
<p>
	<h:outputText value="#{text['testInstance.message.empty']}" rendered="#{testInstanceList.ready==0 and testInstanceList.completed==0}"/>
	<h:outputText value="#{text['testInstance.message.list.has.single.ready']}" rendered="#{testInstanceList.ready==1 and testInstanceList.completed==0}"/> 
	<h:outputText value="#{text['testInstance.message.list.has.all.ready']}" rendered="#{testInstanceList.ready gt 1 and testInstanceList.completed==0}"/> 
	<h:outputText value="#{text['testInstance.message.list.has.only.completed']}" rendered="#{testInstanceList.ready==0 and testInstanceList.completed!=0}"/> 
	<h:outputText value="#{text['testInstance.message.has.both.ready.completed']}" rendered="#{testInstanceList.ready!=0 and testInstanceList.completed!=0}"/> 
</p>

<p>
	<h:outputText value="#{text['testInstance.message.showResults.has.single.show']}" rendered="#{testInstanceList.completed==1 and testInstanceList.maySeeResults==1}"/>
	<h:outputText value="#{text['testInstance.message.showResults.has.all.show']}" rendered="#{testInstanceList.completed gt 1 and testInstanceList.maySeeResults==testInstanceList.completed}"/>
	<h:outputText value="#{text['testInstance.message.showResults.has.both.show.hidden']}" rendered="#{testInstanceList.completed gt 1 and testInstanceList.maySeeResults gt 0 and testInstanceList.maySeeResults lt testInstanceList.completed}"/>
	<h:outputText value="#{text['testInstance.message.showResults.has.single.hide']}" rendered="#{testInstanceList.completed==1 and testInstanceList.maySeeResults==0}"/>
	<h:outputText value="#{text['testInstance.message.showResults.has.all.hide']}" rendered="#{testInstanceList.completed gt 1 and testInstanceList.maySeeResults==0}"/>	 
</p>

	
	<!-- Useful for Debugging--> 
	<!--br/>
	Ready tests are: <h:outputText value="#{testInstanceList.ready}"/><br/>
	Completed tests are: <h:outputText value="#{testInstanceList.completed}"/><br/>
	Number of tests to show is <h:outputText value="#{testInstanceList.maySeeResults}"/-->


<h:form id="editUserInstance">
<h:panelGroup rendered="true">
<div class="tests_background">
<!-- Table with list of test instances for the logged in user -->
<t:dataTable id="testInstances" var="testInstance" value="#{testInstanceList.testInstances}" 
	rows="10" sortColumn="#{testInstanceList.sortColumn}" sortAscending="#{testInstanceList.ascending}" 
	headerClass="standardTable_Header" rowClasses="rowA,rowB" styleClass="mainTable"
    rendered="#{not empty testInstanceList.testInstances}" sortable="true">
    <t:column> 
        <f:facet name="header">
            <t:commandSortHeader columnName="objectId" arrow="true" >
                <h:outputText value="#{text['testInstance.id']}" />
            </t:commandSortHeader>
        </f:facet>
        <h:outputText  value="#{testInstance.objectId}" escape="true" />
            
    </t:column>
    <t:column>
        <f:facet name="header">
            <t:commandSortHeader columnName="testTemplateDescription" arrow="true">
                <h:outputText value="#{text['testInstance.templateDescription']}" />
            </t:commandSortHeader>
        </f:facet>
        <h:outputText value="#{testInstance.testTemplateDescription}" escape="true"/>
    </t:column>
    <t:column>
        <f:facet name="header">
            <t:commandSortHeader columnName="testInstanceStateDesc" arrow="true">
                <h:outputText value="#{text['testInstance.instanceState']}" />
            </t:commandSortHeader>
        </f:facet>
        <h:outputText value="#{testInstance.testInstanceStateDesc}" escape="true" />
    </t:column>
    <t:column style="width: 250px; text-align: right">
        <f:facet name="header">
            <t:commandSortHeader columnName="review" arrow="true">
                <h:outputText value=" " />
            </t:commandSortHeader>
        </f:facet>
		<h:panelGroup layout="block">
			<h:commandButton value="#{textEnv['testInstance.action.take.test']}" action="#{userTest.takeTest}" id="takeTestBtn"  rendered="#{testInstance.testInstanceState.state=='READY'}" styleClass="button_inline" >
				<f:param name="testInstanceObjectId" value="#{testInstance.objectId}"/>
				<f:param name="testScoringAlgorithm" value="#{testInstance.testScoringAlgorithm.objectId}"/>
			</h:commandButton>

			<h:commandButton value="#{text['testInstance.action.display.results']}" action="#{userTest.inlineReport}" rendered="#{testInstance.testInstanceState.state=='COMPLETED' and testInstance.showResult}" styleClass="button_inline" >
				<f:param name="testInstanceObjectId" value="#{testInstance.objectId}"/>
			</h:commandButton>

			<h:commandButton value="#{text['testInstance.action.print.results']}" action="#{userTest.PDFReport}"  rendered="#{testInstance.testInstanceState.state=='COMPLETED' and testInstance.showResult}" styleClass="button_inline" >
				<f:param name="testInstanceObjectId" value="#{testInstance.objectId}"/>
			</h:commandButton>

		</h:panelGroup>
    </t:column>
   </t:dataTable>

<ui:include src="/common/tableFooter.xhtml">
    <ui:param name="tableName" value="testInstances"/> 
</ui:include>

</div>
</h:panelGroup>

<span class="buttongroup">
   <h:commandButton value="#{text['button.done']}" action="mainMenu" id="cancel" immediate="true" styleClass="button_small" />
</span>   
   </h:form>
 
</body>
</f:view>
</html>
